export default {
  namespaced: true,
  state: () => ({
    star: JSON.parse(uni.getStorageSync('star')||'[]')
  }),
  mutations: {
    addToSart(state, goods) {
      const findResult = state.star.findIndex(x => x.goods_id == goods.goods_id)
      if (findResult==-1) {
        state.star.push(goods)
      }else{
        state.star.splice(findResult,1)
      }
      this.commit('m_star/savetoStorage')
    },
    cancelStar(state,goods_id){
      state.star=state.star.filter(x=>x.goods_id!=goods_id)
      this.commit('m_star/savetoStorage')
    },
    savetoStorage(state){
      uni.setStorageSync('star',JSON.stringify(state.star))
    }
  },
  getters: {
  }
}
